﻿namespace HRM.CORE.REPORT
{
    using DevExpress.Utils;
    using DevExpress.XtraPrinting;
    using DevExpress.XtraReports.UI;
    using Dictionary.ERP;
    using HRM.CORE;
    using HRM.CORE.CLASS;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Printing;

    public class rptAllowanceSalary : XtraReport
    {
        private BottomMarginBand BottomMargin;
        private IContainer components;
        private DetailBand Detail;
        private DetailBand Detail1;
        private DetailReportBand DetailReport;
        private GroupFooterBand GroupFooter2;
        private GroupHeaderBand GroupHeader1;
        private HRM_SALARY l_Salary;
        private HRM_SALARY_TABLELIST l_SalaryTableList;
        private string m_Code;
        private string m_EmployeeCode;
        private int m_Level;
        private int m_Month;
        private int m_Order;
        private int m_Year;
        private ReportFooterBand ReportFooter;
        private ReportHeaderBand ReportHeader;
        private TopMarginBand TopMargin;
        private XRTableCell txtAllowanceCode;
        private XRTableCell txtAllowanceName;
        private XRLabel txtEmployeeCode;
        private XRLabel txtInformation;
        private XRTableCell txtMoney;
        private XRTableCell txtOrder;
        private XRLabel txtTitle;
        private XRLabel txtTotal;
        private XRLabel txtUnit;
        private XRLabel xrLabel3;
        private XRLine xrLine1;
        private XRLine xrLine2;
        private XRTable xrTable1;
        private XRTable xrTable4;
        private XRTableCell xrTableCell1;
        private XRTableCell xrTableCell14;
        private XRTableCell xrTableCell16;
        private XRTableCell xrTableCell17;
        private XRTableRow xrTableRow6;
        private XRTableRow xrTableRow7;

        public rptAllowanceSalary()
        {
            this.components = null;
            this.l_Salary = new HRM_SALARY();
            this.l_SalaryTableList = new HRM_SALARY_TABLELIST();
            this.m_Level = 0;
            this.m_Code = "";
            this.m_EmployeeCode = "";
            this.m_Month = 0;
            this.m_Year = 0;
            this.m_Order = 0;
            this.InitializeComponent();
        }

        public rptAllowanceSalary(int Month, int Year, string EmployeeCode)
        {
            this.components = null;
            this.l_Salary = new HRM_SALARY();
            this.l_SalaryTableList = new HRM_SALARY_TABLELIST();
            this.m_Level = 0;
            this.m_Code = "";
            this.m_EmployeeCode = "";
            this.m_Month = 0;
            this.m_Year = 0;
            this.m_Order = 0;
            this.InitializeComponent();
            this.m_Month = Month;
            this.m_Year = Year;
            this.m_EmployeeCode = EmployeeCode;
            this.l_SalaryTableList.Get(this.m_Month, this.m_Year);
        }

        public rptAllowanceSalary(int Level, string Code, int Month, int Year)
        {
            this.components = null;
            this.l_Salary = new HRM_SALARY();
            this.l_SalaryTableList = new HRM_SALARY_TABLELIST();
            this.m_Level = 0;
            this.m_Code = "";
            this.m_EmployeeCode = "";
            this.m_Month = 0;
            this.m_Year = 0;
            this.m_Order = 0;
            this.InitializeComponent();
            this.m_Level = Level;
            this.m_Code = Code;
            this.m_Month = Month;
            this.m_Year = Year;
            this.l_SalaryTableList.Get(this.m_Month, this.m_Year);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.Detail = new DetailBand();
            this.txtInformation = new XRLabel();
            this.txtEmployeeCode = new XRLabel();
            this.xrLine1 = new XRLine();
            this.TopMargin = new TopMarginBand();
            this.BottomMargin = new BottomMarginBand();
            this.ReportHeader = new ReportHeaderBand();
            this.txtTitle = new XRLabel();
            this.txtUnit = new XRLabel();
            this.ReportFooter = new ReportFooterBand();
            this.DetailReport = new DetailReportBand();
            this.Detail1 = new DetailBand();
            this.xrTable1 = new XRTable();
            this.xrTableRow6 = new XRTableRow();
            this.txtOrder = new XRTableCell();
            this.txtAllowanceCode = new XRTableCell();
            this.txtAllowanceName = new XRTableCell();
            this.txtMoney = new XRTableCell();
            this.GroupHeader1 = new GroupHeaderBand();
            this.xrTable4 = new XRTable();
            this.xrTableRow7 = new XRTableRow();
            this.xrTableCell1 = new XRTableCell();
            this.xrTableCell14 = new XRTableCell();
            this.xrTableCell16 = new XRTableCell();
            this.xrTableCell17 = new XRTableCell();
            this.GroupFooter2 = new GroupFooterBand();
            this.txtTotal = new XRLabel();
            this.xrLabel3 = new XRLabel();
            this.xrLine2 = new XRLine();
            this.xrTable1.BeginInit();
            this.xrTable4.BeginInit();
            this.BeginInit();
            this.Detail.Controls.AddRange(new XRControl[] { this.txtInformation, this.txtEmployeeCode, this.xrLine1 });
            this.Detail.HeightF = 30f;
            this.Detail.Name = "Detail";
            this.Detail.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.Detail.TextAlignment = TextAlignment.TopLeft;
            this.txtInformation.Font = new Font("Times New Roman", 11.25f, FontStyle.Bold);
            this.txtInformation.LocationFloat = new PointFloat(396.375f, 5.66666f);
            this.txtInformation.Name = "txtInformation";
            this.txtInformation.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtInformation.SizeF = new SizeF(340.625f, 18.20833f);
            this.txtInformation.StylePriority.UseFont = false;
            this.txtInformation.StylePriority.UseTextAlignment = false;
            this.txtInformation.Text = "txtInformation";
            this.txtInformation.TextAlignment = TextAlignment.MiddleRight;
            this.txtEmployeeCode.Font = new Font("Times New Roman", 11.25f, FontStyle.Bold);
            this.txtEmployeeCode.LocationFloat = new PointFloat(11.45833f, 5.95834f);
            this.txtEmployeeCode.Name = "txtEmployeeCode";
            this.txtEmployeeCode.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtEmployeeCode.SizeF = new SizeF(360.4167f, 17.70833f);
            this.txtEmployeeCode.StylePriority.UseFont = false;
            this.txtEmployeeCode.Text = "txtEmployeeCode";
            this.txtEmployeeCode.BeforePrint += new PrintEventHandler(this.txtEmployeeCode_BeforePrint);
            this.xrLine1.BorderWidth = 0;
            this.xrLine1.ForeColor = Color.DarkGray;
            this.xrLine1.LocationFloat = new PointFloat(11.45833f, 24.87501f);
            this.xrLine1.Name = "xrLine1";
            this.xrLine1.SizeF = new SizeF(725.5416f, 3.125f);
            this.xrLine1.StylePriority.UseBorderWidth = false;
            this.xrLine1.StylePriority.UseForeColor = false;
            this.TopMargin.HeightF = 40f;
            this.TopMargin.Name = "TopMargin";
            this.TopMargin.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.TopMargin.TextAlignment = TextAlignment.TopLeft;
            this.BottomMargin.HeightF = 40f;
            this.BottomMargin.Name = "BottomMargin";
            this.BottomMargin.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.BottomMargin.TextAlignment = TextAlignment.TopLeft;
            this.ReportHeader.Controls.AddRange(new XRControl[] { this.txtTitle, this.txtUnit });
            this.ReportHeader.HeightF = 55f;
            this.ReportHeader.Name = "ReportHeader";
            this.txtTitle.Font = new Font("Times New Roman", 16f, FontStyle.Bold);
            this.txtTitle.LocationFloat = new PointFloat(3.178914E-05f, 3.333321f);
            this.txtTitle.Name = "txtTitle";
            this.txtTitle.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtTitle.SizeF = new SizeF(746.9999f, 30.25001f);
            this.txtTitle.StylePriority.UseFont = false;
            this.txtTitle.StylePriority.UseTextAlignment = false;
            this.txtTitle.Text = "BẢNG LƯƠNG PHỤ CẤP TH\x00c1NG 00/0000";
            this.txtTitle.TextAlignment = TextAlignment.MiddleCenter;
            this.txtUnit.LocationFloat = new PointFloat(4.768372E-05f, 33.58333f);
            this.txtUnit.Name = "txtUnit";
            this.txtUnit.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtUnit.SizeF = new SizeF(746.9999f, 17.70834f);
            this.txtUnit.StylePriority.UseTextAlignment = false;
            this.txtUnit.TextAlignment = TextAlignment.MiddleCenter;
            this.ReportFooter.HeightF = 11f;
            this.ReportFooter.Name = "ReportFooter";
            this.DetailReport.Bands.AddRange(new Band[] { this.Detail1, this.GroupHeader1, this.GroupFooter2 });
            this.DetailReport.Level = 0;
            this.DetailReport.Name = "DetailReport";
            this.Detail1.Controls.AddRange(new XRControl[] { this.xrTable1 });
            this.Detail1.HeightF = 20.20833f;
            this.Detail1.Name = "Detail1";
            this.xrTable1.BorderColor = Color.Gray;
            this.xrTable1.Borders = BorderSide.Bottom | BorderSide.Right | BorderSide.Left;
            this.xrTable1.LocationFloat = new PointFloat(9.999998f, 0f);
            this.xrTable1.Name = "xrTable1";
            this.xrTable1.Rows.AddRange(new XRTableRow[] { this.xrTableRow6 });
            this.xrTable1.SizeF = new SizeF(726.9999f, 20.20833f);
            this.xrTable1.StylePriority.UseBorderColor = false;
            this.xrTable1.StylePriority.UseBorders = false;
            this.xrTableRow6.Cells.AddRange(new XRTableCell[] { this.txtOrder, this.txtAllowanceCode, this.txtAllowanceName, this.txtMoney });
            this.xrTableRow6.Name = "xrTableRow6";
            this.xrTableRow6.Weight = 1.0;
            this.txtOrder.Name = "txtOrder";
            this.txtOrder.StylePriority.UseTextAlignment = false;
            this.txtOrder.Text = "txtOrder";
            this.txtOrder.TextAlignment = TextAlignment.MiddleLeft;
            this.txtOrder.Weight = 0.38004898337708332;
            this.txtOrder.BeforePrint += new PrintEventHandler(this.txtOrder_BeforePrint);
            this.txtAllowanceCode.Name = "txtAllowanceCode";
            this.txtAllowanceCode.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            this.txtAllowanceCode.StylePriority.UsePadding = false;
            this.txtAllowanceCode.StylePriority.UseTextAlignment = false;
            this.txtAllowanceCode.Text = "txtAllowanceCode";
            this.txtAllowanceCode.TextAlignment = TextAlignment.MiddleLeft;
            this.txtAllowanceCode.Weight = 0.53715153798689241;
            this.txtAllowanceName.Name = "txtAllowanceName";
            this.txtAllowanceName.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            this.txtAllowanceName.StylePriority.UsePadding = false;
            this.txtAllowanceName.StylePriority.UseTextAlignment = false;
            this.txtAllowanceName.Text = "txtAllowanceName";
            this.txtAllowanceName.TextAlignment = TextAlignment.MiddleLeft;
            this.txtAllowanceName.Weight = 1.2465074713101072;
            this.txtMoney.Name = "txtMoney";
            this.txtMoney.Padding = new PaddingInfo(0, 4, 0, 0, 100f);
            this.txtMoney.StylePriority.UsePadding = false;
            this.txtMoney.StylePriority.UseTextAlignment = false;
            this.txtMoney.Text = "txtMoney";
            this.txtMoney.TextAlignment = TextAlignment.MiddleRight;
            this.txtMoney.Weight = 0.82696689949210056;
            this.GroupHeader1.Controls.AddRange(new XRControl[] { this.xrTable4 });
            this.GroupHeader1.HeightF = 21.875f;
            this.GroupHeader1.Name = "GroupHeader1";
            this.xrTable4.AnchorVertical = VerticalAnchorStyles.Bottom;
            this.xrTable4.BorderColor = Color.Gray;
            this.xrTable4.Borders = BorderSide.All;
            this.xrTable4.LocationFloat = new PointFloat(9.999998f, 0f);
            this.xrTable4.Name = "xrTable4";
            this.xrTable4.Rows.AddRange(new XRTableRow[] { this.xrTableRow7 });
            this.xrTable4.SizeF = new SizeF(726.9999f, 21.875f);
            this.xrTable4.StylePriority.UseBorderColor = false;
            this.xrTable4.StylePriority.UseBorders = false;
            this.xrTable4.StylePriority.UseTextAlignment = false;
            this.xrTable4.TextAlignment = TextAlignment.MiddleCenter;
            this.xrTableRow7.Cells.AddRange(new XRTableCell[] { this.xrTableCell1, this.xrTableCell14, this.xrTableCell16, this.xrTableCell17 });
            this.xrTableRow7.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.xrTableRow7.Name = "xrTableRow7";
            this.xrTableRow7.StylePriority.UseFont = false;
            this.xrTableRow7.Weight = 1.0;
            this.xrTableCell1.CanGrow = false;
            this.xrTableCell1.Name = "xrTableCell1";
            this.xrTableCell1.Text = "STT";
            this.xrTableCell1.Weight = 0.38123392848922077;
            this.xrTableCell14.CanGrow = false;
            this.xrTableCell14.Name = "xrTableCell14";
            this.xrTableCell14.Text = "M\x00e3 phụ cấp";
            this.xrTableCell14.Weight = 0.538826501864105;
            this.xrTableCell16.CanGrow = false;
            this.xrTableCell16.Name = "xrTableCell16";
            this.xrTableCell16.Text = "T\x00ean phụ cấp";
            this.xrTableCell16.Weight = 1.25039403079055;
            this.xrTableCell17.CanGrow = false;
            this.xrTableCell17.Name = "xrTableCell17";
            this.xrTableCell17.Text = "Số tiền";
            this.xrTableCell17.Weight = 0.82954553885612436;
            this.GroupFooter2.Controls.AddRange(new XRControl[] { this.txtTotal, this.xrLabel3, this.xrLine2 });
            this.GroupFooter2.HeightF = 39f;
            this.GroupFooter2.Name = "GroupFooter2";
            this.txtTotal.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.txtTotal.LocationFloat = new PointFloat(107.3857f, 7.291662f);
            this.txtTotal.Name = "txtTotal";
            this.txtTotal.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtTotal.SizeF = new SizeF(130.5756f, 17.70833f);
            this.txtTotal.StylePriority.UseFont = false;
            this.txtTotal.Text = "txtTotal";
            this.txtTotal.BeforePrint += new PrintEventHandler(this.txtTotal_BeforePrint);
            this.xrLabel3.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.xrLabel3.LocationFloat = new PointFloat(12.45834f, 7.291662f);
            this.xrLabel3.Name = "xrLabel3";
            this.xrLabel3.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.xrLabel3.SizeF = new SizeF(90.92734f, 17.70833f);
            this.xrLabel3.StylePriority.UseFont = false;
            this.xrLabel3.Text = "Lương Chuẩn:";
            this.xrLine2.BorderWidth = 0;
            this.xrLine2.ForeColor = Color.DarkGray;
            this.xrLine2.LocationFloat = new PointFloat(9.5f, 25f);
            this.xrLine2.Name = "xrLine2";
            this.xrLine2.SizeF = new SizeF(725.5416f, 3.125f);
            this.xrLine2.StylePriority.UseBorderWidth = false;
            this.xrLine2.StylePriority.UseForeColor = false;
            base.Bands.AddRange(new Band[] { this.Detail, this.TopMargin, this.BottomMargin, this.ReportHeader, this.ReportFooter, this.DetailReport });
            base.Font = new Font("Times New Roman", 9.75f);
            base.Margins = new Margins(40, 40, 40, 40);
            this.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            base.PageHeight = 0x491;
            base.PageWidth = 0x33b;
            base.PaperKind = PaperKind.A4;
            base.Version = "9.3";
            this.BeforePrint += new PrintEventHandler(this.rptListEmployee_BeforePrint);
            this.xrTable1.EndInit();
            this.xrTable4.EndInit();
            this.EndInit();
        }

        private void LoadAllData()
        {
            DataSet set = new DataSet();
            DataTable table = new DataTable();
            table = this.l_Salary.GetList(this.m_Level, this.m_Code, this.l_SalaryTableList.SalaryTableListID);
            if (this.m_Level != 0)
            {
                if (this.m_Level == 1)
                {
                    HRM_BRANCH hrm_branch = new HRM_BRANCH();
                    hrm_branch.Get(this.m_Code);
                    this.txtUnit.Text = "Đơn vị: " + hrm_branch.BranchName;
                }
                else if (this.m_Level == 2)
                {
                    HRM_DEPARTMENT hrm_department = new HRM_DEPARTMENT();
                    hrm_department.Get(this.m_Code);
                    this.txtUnit.Text = "Đơn vị: " + hrm_department.DepartmentName;
                }
                else if (this.m_Level == 3)
                {
                    HRM_GROUP hrm_group = new HRM_GROUP();
                    hrm_group.Get(this.m_Code);
                    this.txtUnit.Text = "Đơn vị: " + hrm_group.GroupName;
                }
            }
            set.Tables.Add(table);
            base.DataSource = set;
            this.txtEmployeeCode.DataBindings.Add("Text", base.DataSource, "EmployeeCode");
        }

        private void LoadData()
        {
            this.txtEmployeeCode.Text = this.m_EmployeeCode;
        }

        private void rptListEmployee_BeforePrint(object sender, PrintEventArgs e)
        {
            this.txtTitle.Text = "BẢNG LƯƠNG PHỤ CẤP TH\x00c1NG " + this.m_Month.ToString() + "/" + this.m_Year.ToString();
            if (this.m_EmployeeCode != "")
            {
                this.LoadData();
            }
            else
            {
                this.LoadAllData();
            }
            CreateHeaderReport.CreateHeader(this.ReportHeader);
            CreateFooterReport.CreateFooter("IsSalary", this.ReportFooter, this);
        }

        private void txtEmployeeCode_BeforePrint(object sender, PrintEventArgs e)
        {
            this.m_Order = 0;
            DataSet set = new DataSet();
            DataTable list = new DataTable();
            list = new HRM_SALARY_ALLOWANCE().GetList(this.l_SalaryTableList.SalaryTableListID, this.txtEmployeeCode.Text);
            set.Tables.Add(list);
            this.DetailReport.DataSource = set;
            this.txtAllowanceCode.DataBindings.Add("Text", this.DetailReport.DataSource, "AllowanceCode");
            this.txtAllowanceName.DataBindings.Add("Text", this.DetailReport.DataSource, "AllowanceName");
            this.txtMoney.DataBindings.Add("Text", this.DetailReport.DataSource, "Money", "{0:##,##0}");
            HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
            hrm_employee.Get(this.m_EmployeeCode = this.txtEmployeeCode.Text);
            this.txtEmployeeCode.Text = hrm_employee.EmployeeCode + " - " + hrm_employee.FirstName.ToUpper() + " " + hrm_employee.LastName.ToUpper();
            this.txtInformation.Text = "Lương căn bản: " + hrm_employee.BasicSalary.ToString("#,#") + " (Hsl: " + hrm_employee.CoefficientSalary.ToString() + ")";
        }

        private void txtOrder_BeforePrint(object sender, PrintEventArgs e)
        {
            this.m_Order++;
            this.txtOrder.Text = this.m_Order.ToString();
        }

        private void txtTotal_BeforePrint(object sender, PrintEventArgs e)
        {
            HRM_SALARY hrm_salary = new HRM_SALARY();
            hrm_salary.Get(this.l_SalaryTableList.SalaryTableListID, this.m_EmployeeCode);
            this.txtTotal.Text = hrm_salary.TotalSalary.ToString("#,# VNĐ");
        }
    }
}

